from sklearn.svm import SVR
from sklearn.svm import LinearSVC
import matplotlib.pyplot as plt
import numpy as np

x=np.random.rand(120,1)*15
x_train=np.sort(x,axis=0)
y_train = np.sin(x_train)

y_train[::5]+=np.random.randn(24,1)

svr_linear = SVR(kernel='linear')
rbf_linear = SVR(kernel='rbf')
poly_linear = SVR(kernel='poly')

x_test = np.arange(0,15,0.01)[:,np.newaxis]

y_linear=svr_linear.fit(x_train,y_train.ravel()).predict(x_test)
y_rbf=rbf_linear.fit(x_train,y_train.ravel()).predict(x_test)
y_poly=poly_linear.fit(x_train,y_train.ravel()).predict(x_test)

plt.figure(figsize=(16,9))
plt.scatter(x_train,y_train)

plt.plot(x_test,y_linear,label="linear")
plt.plot(x_test,y_rbf,label="rbf")
plt.plot(x_test,y_poly,label="poly")
plt.legend()
# plt.plot(x_train,y_train)
plt.ylim(-3,3)
plt.savefig("4svm.png")